package polimi.reds.optimizer.test;


/**
 * Class AceLink This class represents a link between two nodes. NOTE: This
 * class is not mutable
 * 
 * @author Daniele Joseph Dubois
 */
public class Edge {

	/** First end point of the link */
	private Broker node1 = null;

	/** Second end point of the link */
	private Broker node2 = null;

	/**
	 * This constructor creates a new link using the two specified nodes as end
	 * points.
	 * 
	 * @param node1
	 *            First node
	 * @param node2
	 *            Second node
	 */
	public Edge(Broker node1, Broker node2) {
		this.node1 = node1;
		this.node2 = node2;
	}

	/**
	 * This method gets the first node of the link
	 * 
	 * @return First end point of the link
	 */
	public Broker getNode1() {
		return node1;
	}

	/**
	 * This method gets the second node of the link
	 * 
	 * @return Second end point of the link
	 */
	public Broker getNode2() {
		return node2;
	}

	/**
	 * This method checks if this link is equal to another link regardless the
	 * direction of the link. This means that two links are recognized equal
	 * even if they have inverted end points.
	 * 
	 * @param o
	 *            Link to be compared
	 * @return true if the specified link is equivalent to this, false otherwise
	 */
	public boolean equals(Object o) {

		if (o instanceof Edge) {
			Edge link = (Edge) o;
			if ((link.getNode1().equals(node2) && link.getNode2().equals(node1))
					|| (link.getNode1().equals(node1) && link.getNode2()
							.equals(node2))) {
				return true;
			} else {
				return false;
			}
		}

		return super.equals(o);
	}
	
	public String toString() {
		return node1 + " <-> " + node2;
	}
}